package com.yanxu;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.nio.charset.Charset;
import java.util.List;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2023/11/18-2023
 * @Description: 生产者实现 延迟消息
 */
public class ProducerSample03 {
    public static void main(String[] args) {
        DefaultMQProducer producer=new DefaultMQProducer("pg1");
        producer.setNamesrvAddr("192.168.1.31:9876");

        try {
            producer.start();

            String messageTex="{\n" +
                    "  \"id\": 1001,\n" +
                    "  \"type\": \"site\",\n" +
                    "  \"name\": \"Runoob\",\n" +
                    "  \"description\": \"https://www.runoob.com\",\n" +
                    "  \"price\": 2.55\n" +
                    "}\n";
            Message message = new Message("", "", messageTex.getBytes(Charset.defaultCharset()));
            message.setDelayTimeLevel(5);
            SendResult result = producer.send(message);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            producer.shutdown();
        }
    }
}